package com.atguigu.gmall.product.controller;

import com.atguigu.gmall.common.result.Result;
import com.atguigu.gmall.model.product.BaseTrademark;
import com.atguigu.gmall.product.service.BaseTrademarkService;
import com.atguigu.gmall.product.service.ManageService;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/admin/product/baseTrademark")
public class BaseTradeMarkController {

    @Autowired
    private ManageService manageService;

    @Autowired
    private BaseTrademarkService baseTrademarkService;

    //  /admin/product/baseTrademark/{page}/{limit}
    @GetMapping("/{page}/{limit}")
    public Result getTradeMarkList(@PathVariable Long page,
                                   @PathVariable Long limit) {
        //  创建对象
        Page<BaseTrademark> baseTrademarkPage = new Page<>(page, limit);
        IPage<BaseTrademark> iPage = this.baseTrademarkService.getTradeMarkList(baseTrademarkPage);
        //  返回数据
        return Result.ok(iPage);

    }


    //  /admin/product/baseTrademark/remove/{id}
    @DeleteMapping("/remove/{id}")
    public Result removeBaseTrademarkById(@PathVariable Long id) {
        //  调用服务层
        //  this.baseTrademarkService.deleteById(id);
        this.baseTrademarkService.removeById(id);

        return Result.ok();
    }

    //  /admin/product/baseTrademark/save
    //  Json ---> javaObject
    @PostMapping("save")
    public Result saveBastTradeMark(@RequestBody BaseTrademark baseTrademark){
        //  调用服务层
        this.baseTrademarkService.save(baseTrademark);
        return Result.ok();
    }

    //  /admin/product/baseTrademark/get/{id}
    @GetMapping("/get/{id}")
    public Result getById(@PathVariable Long id){

        //  调用访问
        BaseTrademark baseTrademark = this.baseTrademarkService.getById(id);
        //  返回
        return Result.ok(baseTrademark);
    }

    //  /admin/product/baseTrademark/update
    @PutMapping("update")
    public Result updateBaseTrademark(@RequestBody BaseTrademark baseTrademark){
        //  调用方法
        this.baseTrademarkService.updateById(baseTrademark);
        return Result.ok();
    }




}
